﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.Security;
using BusinessLogic;
using CentalineWeb;
using CentalineWeb.Common;

namespace CentalineWeb
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            //网站启动时,获取所有未受理的工单列表.如果提交时间已经超过自动受理时间,则立即进行自动受理.否则，定时受理
            var timer = new WorkTimer();
            var sql = "select * from repairs where statusid=1";
            var list = new RepairManager().ExecuteSql(sql) as DataTable;
            if (list.Rows.Count <= 0) return;
            foreach (DataRow row in list.Rows)
            {
                var committime = Convert.ToDateTime(row["applytime"]);
                var configtime = Convert.ToInt32(ConfigurationManager.AppSettings["delayAsignTime"]);
                var subMilli = DateTime.Now.Subtract(committime).TotalMilliseconds;
                if (subMilli > configtime)
                {
                    timer.AutoAsign(row["wordorderid"].ToString());
                }
                else
                {
                 timer.NewTimer(row["wordorderid"].ToString(),(int)subMilli);   
                }
            }

        }

        void Application_End(object sender, EventArgs e)
        {
            //  在应用程序关闭时运行的代码

        }

        void Application_Error(object sender, EventArgs e)
        {
            // 在出现未处理的错误时运行的代码

        }
    }
}
